/*
	向所有客户端广播消息
*/

var http = require("http");
var express = require("express");
var sio = require("socket.io");

var app = express();
var server = http.createServer(app).listen(1337);

app.get('/', function(req, res) {
	res.sendfile('./11_broadcastClient.html');
});

var socketSer = sio.listen(server);
var names = [];

socketSer.sockets.on('connection', function(socket) {

	socket.emit('login', names);
	socket.on('login', function(name) {
		names.push(name);
		// 方式1、
		socketSer.sockets.emit('login', names);

		// 方式2、 等效
		// socket.emit('login', names);
		// socket.broadcast.emit('login', names);
	});

});